//
//  CellOfShopForSelectDeatil.m
//  PetAPP
//
//  Created by apple on 16/2/24.
//  Copyright © 2016年 Yuming. All rights reserved.
//

#import "CellOfShopForSelectDeatil.h"
#import "ModelOfShopForDetail.h"
#import <YYWebImage.h>

@interface CellOfShopForSelectDeatil ()

@property (nonatomic, retain) UIImageView *imageViewOfPic;

@property (nonatomic, retain) UILabel *labelOfEmpty;

@property (nonatomic, retain) UILabel *labelOfName;

@property (nonatomic, retain) UILabel *labelOfMarketPrice;

@property (nonatomic, retain) UILabel *labelOfShopPrice;

@property (nonatomic, retain) UIView *viewOfMarketGrayLine;

@end

@implementation CellOfShopForSelectDeatil

- (void)dealloc {

    [_viewOfMarketGrayLine release];
    [_imageViewOfPic release];
    [_labelOfEmpty release];
    [_labelOfName release];
    [_labelOfMarketPrice release];
    [_labelOfShopPrice release];
    [super dealloc];

}

- (instancetype)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    
    return self;

}

- (void)createSubViews {
    
    self.imageViewOfPic = [[UIImageView alloc] init];
    [self.contentView addSubview:_imageViewOfPic];
    [_imageViewOfPic release];
    
    
    self.labelOfEmpty = [[UILabel alloc] init];
    [self.contentView addSubview:_labelOfEmpty];
    [_labelOfEmpty release];
    self.labelOfEmpty.text = @"  抢光啦！";
    self.labelOfEmpty.textColor = [UIColor whiteColor];
    self.labelOfEmpty.textAlignment = NSTextAlignmentCenter;
    
    UIBezierPath *backgroundPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 3, 80, 80) cornerRadius:40];
    
    self.labelOfEmpty.layer.shadowPath = backgroundPath.CGPath;
    self.labelOfEmpty.layer.shadowOpacity = 0.4;
    self.labelOfEmpty.layer.shadowRadius = 0;
    self.labelOfEmpty.layer.shadowColor = [UIColor blackColor].CGColor;
    
    
    self.labelOfName = [[UILabel alloc] init];
    [self.contentView addSubview:_labelOfName];
    [_labelOfName release];
    self.labelOfName.font = [UIFont systemFontOfSize:15];
    self.labelOfName.numberOfLines = 2;
    
    
    
    self.labelOfShopPrice = [[UILabel alloc] init];
    [self.contentView addSubview:_labelOfShopPrice];
    [_labelOfShopPrice release];
    self.labelOfShopPrice.textColor = [UIColor brownColor];
    self.labelOfShopPrice.font = [UIFont systemFontOfSize:20];
    
    
    self.labelOfMarketPrice = [[UILabel alloc] init];
    [self.contentView addSubview:_labelOfMarketPrice];
    [_labelOfMarketPrice release];
    self.labelOfMarketPrice.textColor = [UIColor grayColor];
    self.labelOfMarketPrice.font = [UIFont systemFontOfSize:15];
    
    
    UIView *grayLine = [[UIView alloc] init];
    [self.contentView addSubview:grayLine];
    [grayLine release];
    grayLine.frame = CGRectMake(5, 175, self.contentView.frame.size.width - 10, 1);
    grayLine.layer.borderColor = [UIColor grayColor].CGColor;
    grayLine.layer.borderWidth = 1;
    
    
    self.viewOfMarketGrayLine = [[UIView alloc] init];
    [self.contentView addSubview:_viewOfMarketGrayLine];
    [_viewOfMarketGrayLine release];
    self.viewOfMarketGrayLine.layer.borderColor = [UIColor grayColor].CGColor;
    self.viewOfMarketGrayLine.layer.borderWidth = 4;
    
    

}


- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {

    self.imageViewOfPic.frame = CGRectMake(0, 0, self.contentView.frame.size.width, 135);
    
    self.labelOfEmpty.frame = CGRectMake(0, 0, 80, 80);
    self.labelOfEmpty.center = self.imageViewOfPic.center;
    
    
    self.labelOfName.frame = CGRectMake(5, 135, self.contentView.frame.size.width - 10, 37);
    
    
    self.labelOfShopPrice.frame = CGRectMake(5, 177, self.contentView.frame.size.width / 2 - 10, 23);
    

}

- (void)handleDataWithModel:(ModelOfShopForDetail *)model {
    if ([model.goods_number isEqualToString:@"0"]) {
        self.labelOfEmpty.hidden = NO;
    }else {
        self.labelOfEmpty.hidden = YES;
    }

    if ([[model.goods_thumb substringToIndex:21] isEqualToString:@"http://ts.leepet.com/"]) {
        NSString *str = [NSString stringWithFormat:@"http://ts.leepet.com/%@", model.app_img];
        if ([model.goods_id isEqualToString:@"10737"]) {
            str = @"http://ts.leepet.com/images/201602/thumb_img/10737_thumb_G_1456271561121.jpg";
        }
//        self.imageViewOfPic.yy_imageURL = [NSURL URLWithString:str];
        [self.imageViewOfPic yy_setImageWithURL:[NSURL URLWithString:str] options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation];

    }else{
//        self.imageViewOfPic.yy_imageURL = [NSURL URLWithString:model.goods_thumb];
        [self.imageViewOfPic yy_setImageWithURL:[NSURL URLWithString:model.goods_thumb] options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation];

    }

    
        self.labelOfName.text = model.goods_name;
    

    
    self.labelOfShopPrice.text = [NSString stringWithFormat:@"￥%@", model.shop_price];

    
    
    self.labelOfMarketPrice.text = [NSString stringWithFormat:@"￥%@", model.market_price];

    
    
    
    CGRect labelOfMarkWidth = [self.labelOfMarketPrice.text boundingRectWithSize:CGSizeMake(0, 23) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15]} context:nil];
    self.labelOfMarketPrice.frame = CGRectMake(self.contentView.frame.size.width / 2 - 20 , 177, labelOfMarkWidth.size.width, 23);
    
    self.viewOfMarketGrayLine.frame = CGRectMake(self.contentView.frame.size.width / 2 - 20, 187, labelOfMarkWidth.size.width + 4, 1.5);
    

    
}


@end
